import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import postCssPxToRem from 'wa-postcss-pxtorem'
import Unocss from 'unocss/vite'
import fs from 'node:fs'
import viteCompression from 'vite-plugin-compression'

console.log('你知道吗,如果你想使用自适应单位,默认可以使用rpx')

const httpsOptions = {
  key: fs.readFileSync('.\\node_modules\\@wagq\\wa-cli\\config\\ssl\\key.pem'),
  cert: fs.readFileSync('.\\node_modules\\@wagq\\wa-cli\\config\\ssl\\cert.pem'),
}

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react(),
    Unocss(),
    viteCompression({
      threshold: 1024000, // 对大于 1mb 的文件进行压缩
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve('./src'),
      '@/*': path.resolve('./src/*'),
    },
  },
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 32,
          propList: ['*'],
          selectorBlackList: ['./to', 'html'], // to开头的不进行转换,
          exclude: '/node_modules',
          unit: 'rpx',
        }),
      ],
    },
    preprocessorOptions: {
      scss: {
        additionalData: '@use "./src/styles/main.scss";',
        api: 'modern-compiler', // or 'modern'
      },
    },
  },
  server: {
    port: 9090,
    https: httpsOptions,
  },
})
